package com.example.june.zhanghaoguanli;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.Toast;

import com.longfly_example.e_scale.R;
import com.longfly_example.e_scale.Scale_Activity;

import java.util.ArrayList;
import java.util.List;

public class shopping extends AppCompatActivity {
    ListView mListView;
    ListView qdListView;

    List<LianxirenBean_qd> itemBeanList = new ArrayList<>();
    ;
    private String jiner;
    private String weight;
    private String name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shopping);

        Button jiesuan = (Button) findViewById(R.id.jiesuan);
        Button BT_search = (Button) findViewById(R.id.BT_search);
        final EditText et_search = (EditText) findViewById(R.id.ET_search);


        Adapter adapter = new Adapter();
        adapter.init();
        Adapter_qd adapter_qd = new Adapter_qd();
        adapter_qd.init();


        BT_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String search;
                mListView.setAdapter(null);
                search = et_search.getText().toString();
            }
        });
        jiesuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(shopping.this, Activity_play.class);
                shopping.this.startActivity(intent);

            }
        });


    }

    public class Adapter_qd {


        public void init() {

            Intent intent = getIntent();
            jiner = intent.getStringExtra("jiner");
            weight = intent.getStringExtra("weight");
            name = intent.getStringExtra("name");

            LianxirenBean_qd beanQd = new LianxirenBean_qd(name, weight, jiner);

            /*itemBeanList.add(new LianxirenBean_qd(name, weight, jiner));
            itemBeanList.add(new LianxirenBean_qd(name, weight, jiner));
            itemBeanList.add(new LianxirenBean_qd(name, weight, jiner));*/

            qdListView = (ListView) findViewById(R.id.LV_qd);
            //设置ListView的数据适配器
            Myadapter_qd myadapter_qd = new Myadapter_qd(shopping.this, itemBeanList);

            myadapter_qd.addList(beanQd);

            qdListView.setAdapter(myadapter_qd);
            myadapter_qd.notifyDataSetChanged();

        }
    }

    public class Adapter {
        public void init() {

            List<ItemBean> itemBeanList = new ArrayList<>();
            itemBeanList.add(new ItemBean(R.drawable.timssg, "9.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.tieemg, "8.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.timggg, "12.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.banana, "3.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.caomei, "8.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.huolongguo, "5.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.lanmei, "18.7元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.putao, "15.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.qiyiguo, "12.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.xigua, "4.3元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.xueli, "6.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.liulian, "26.9元/kg", "单价："));
            itemBeanList.add(new ItemBean(R.drawable.mugua, "7.9元/kg", "单价："));
            mListView = (ListView) findViewById(R.id.lv_main);

            //设置ListView的数据适配器
            mListView.setAdapter(new Myadapter(shopping.this, itemBeanList));
            mListView.setOnItemClickListener(myListItemClickListener);
        }

    }

    /*
        AdapterView.OnItemClickListener myListItemClickListener = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(shopping.this, Scale_Activity.class);
                startActivity(intent);
            }
        };
        */
    AdapterView.OnItemClickListener myListItemClickListener = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int postion,
                                long id) {
            // TODO Auto-generated method stub
            switch (postion) {
                case 0:
                    Intent intent = new Intent(shopping.this, Scale_Activity.class);
                    intent.putExtra("pg", "9.9");
                    intent.putExtra("name", "苹果");
                    startActivity(intent);

                    break;
                case 1:
                    Intent intent1 = new Intent(shopping.this, Scale_Activity.class);
                    intent1.putExtra("pg", "8.9");
                    intent1.putExtra("name", "柠檬");
                    startActivity(intent1);

                    break;
                case 2:
                    Intent intent2 = new Intent(shopping.this, Scale_Activity.class);
                    intent2.putExtra("pg", "12.9");
                    intent2.putExtra("name", "橙子");
                    startActivity(intent2);

                    break;
                case 3:
                    Intent intent3 = new Intent(shopping.this, Scale_Activity.class);
                    intent3.putExtra("pg", "3.9");
                    intent3.putExtra("name", "香蕉");
                    startActivity(intent3);
                case 4:
                    Intent intent4 = new Intent(shopping.this, Scale_Activity.class);
                    intent4.putExtra("pg", "8.9");
                    intent4.putExtra("name", "草莓");
                    startActivity(intent4);

                    break;
                case 5:
                    Intent intent5 = new Intent(shopping.this, Scale_Activity.class);
                    intent5.putExtra("pg", "5.9");
                    intent5.putExtra("name", "火龙果");
                    startActivity(intent5);

                    break;
                case 6:
                    Intent intent6 = new Intent(shopping.this, Scale_Activity.class);
                    intent6.putExtra("pg", "18.7");
                    intent6.putExtra("name", "蓝莓");
                    startActivity(intent6);

                    break;
                case 7:
                    Intent intent7 = new Intent(shopping.this, Scale_Activity.class);
                    intent7.putExtra("pg", "15.9");
                    intent7.putExtra("name", "葡萄");
                    startActivity(intent7);
                case 8:
                    Intent intent8 = new Intent(shopping.this, Scale_Activity.class);
                    intent8.putExtra("pg", "12.9");
                    intent8.putExtra("name", "奇异果");
                    startActivity(intent8);

                    break;
                case 9:
                    Intent intent9 = new Intent(shopping.this, Scale_Activity.class);
                    intent9.putExtra("pg", "4.3");
                    intent9.putExtra("name", "西瓜");
                    startActivity(intent9);

                    break;
                case 10:
                    Intent intent10 = new Intent(shopping.this, Scale_Activity.class);
                    intent10.putExtra("pg", "6.9");
                    intent10.putExtra("name", "雪梨");
                    startActivity(intent10);

                    break;
                case 11:
                    Intent intent11 = new Intent(shopping.this, Scale_Activity.class);
                    intent11.putExtra("pg", "26.9");
                    intent11.putExtra("name", "榴莲");
                    startActivity(intent11);
                    break;
                case 12:
                    Intent intent12 = new Intent(shopping.this, Scale_Activity.class);
                    intent12.putExtra("pg", "7.9");
                    intent12.putExtra("name", "木瓜");
                    startActivity(intent12);
                    break;
                default:
                    break;
            }
        }
    };
}
